package com.junmiao.A.postProcess;

import com.junmiao.A.stock.constants.Constants;
import com.junmiao.A.stockModel.SinaGGTJBean;

public class SinaGGTJPostProcess {

	public static SinaGGTJBean postSinaGGTJBeanProcess(String resp){
		
	 	SinaGGTJBean ggtj = new SinaGGTJBean();
	 	
	 	//Get Stock Name and No
		int b = resp.indexOf("title");
		int eb = resp.indexOf("_个股体检_新浪网");
		
		if(b < 0 || eb < 0 || (eb-b)< 8){
			return null;
		}
		
		String stock = resp.substring(b+6,eb);
		String stockNo = stock.substring(stock.length()-7,stock.length()-1);
		String stockName = stock.substring(0, stock.length()-8);
		
		ggtj.setStockNo(stockNo);
		ggtj.setStockName(stockName);
		
		
		//Get money flow
		int j =  resp.indexOf("机构资金进出");
		
		if(j<0){
			
			resetGGTJBean(ggtj);
			
		}else
		{
			String tmp =  resp.substring(j+10);
			
			int t = tmp.indexOf(":");
			
			if(t<0 || t>60){
				
				resetGGTJBean(ggtj);
			}else{
				
				String tmp1 = tmp.substring(t+1);
				
				int q = tmp1.indexOf(">");
				int w = tmp1.indexOf("<");
				
				String value = tmp1.substring(q+1,w-1);
				ggtj.setOrg_hold_today(value);
				
				
				String next = tmp1.substring(w+1);
				
				t = next.indexOf(":");
				
				if(t<0){
					
					resetGGTJBean(ggtj);
				}else{
					
					String tmp2 = next.substring(t+1);
					
					q = tmp2.indexOf(">");
					w = tmp2.indexOf("<");
					
					value = tmp2.substring(q+1,w-1);
					ggtj.setOrg_hold_5(value);
					
					next = tmp2.substring(w+1);
					t = next.indexOf(":");
					
					if(t<0){
						
						resetGGTJBean(ggtj);
					}else{
						
						String tmp3 = next.substring(t+1);
						
						q = tmp3.indexOf(">");
						w = tmp3.indexOf("<");
						
						value = tmp3.substring(q+1,w-1);
						ggtj.setIndiv_hold_today(value);
						
						next =  tmp3.substring(w+1);
						
						t = next.indexOf(":");
						
						if(t<0){
							
							resetGGTJBean(ggtj);
						}else{
							
							String tmp4 = next.substring(t+1);
							
							q = tmp4.indexOf(">");
							w = tmp4.indexOf("<");
							
							value = tmp4.substring(q+1,w-1);
							ggtj.setIndiv_hold_5(value);
						
						}
					}
					
				}
				
			}
		}
		
		//Get Stock org hold
		int t = resp.indexOf("机构介入比例");

		if(t<0)
		{
			ggtj.setStock_org_hold(Constants.NO_FOUND_ORG_SHARE_HOLD);
		}else
		{
			String percent = resp.substring(t+6,t+10);
			ggtj.setStock_org_hold(percent);
		}
		    
			
		
		return ggtj;
			
	}
	
	public static void resetGGTJBean(SinaGGTJBean ggtj)
	{
		ggtj.setIndiv_hold_5("0");
		ggtj.setIndiv_hold_today("0");
		ggtj.setOrg_hold_5("0");
		ggtj.setOrg_hold_today("0");
		
	}
	
}
